# -*- coding: utf-8 -*-
from datetime import timedelta
from jms_hi.ods.oms.yl_oms_order_performance_main_hi import jms_ods__yl_oms_order_performance_main_hi
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dwd__dwd_oms_order_performance_main_base_hi = SparkSqlOperator(
    task_id='jms_dwd__dwd_oms_order_performance_main_base_hi',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    task_concurrency=1,
    pool_slots=7,
    master='yarn',
    name='jms_dwd__dwd_oms_order_performance_main_base_hi_{{ execution_date | date_add(1) | cst_hour }}',
    sql='jms_hi/dwd/oms/dwd_oms_order_performance_main_base_hi/execute.sql',
    driver_cores=2 , 
    driver_memory='3G' , 
    executor_cores=2 , 
    executor_memory='4G' ,
    depends_on_past=True,
    num_executors=2 , 
    conf={'spark.dynamicAllocation.enabled'                  : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                    : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 2 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '1G' , 
          'spark.sql.shuffle.partitions'                     : 200,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 1000,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 1000,  # 每天生成 20 个分区
              'hive.optimize.bucketmapjoin': 'true',
              'hive.optimize.bucketmapjoin.sortedmerge': 'true',
              'hive.input.format': 'org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat',
              },
    yarn_queue='pro_hi',
    execution_timeout=timedelta(hours=1),
)

jms_dwd__dwd_oms_order_performance_main_base_hi << jms_ods__yl_oms_order_performance_main_hi
